package edu.vcu.csl.ess;

import java.util.ArrayList;
import java.io.*;

public class JavaCodeParser {
	public static boolean isAlpha(char c) {
		return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
	}

	public static boolean isDigit(char c) {
		return ((c >= '0') && (c <= '9'));
	}

	public static boolean isUnderscore(char c) {
		return (c == '_');
	}

	public static final String keywords[] 
	                                    = {"abstract", "default", "if",         "private",    "this",
		"boolean",  "do",      "implements", "protected",  "throw",
		"break",    "double",  "import",     "public",     "throws",
		"byte",     "else",    "instanceof", "return",     "transient",
		"case",     "extends", "int",        "short",      "try",
		"catch",    "final",   "interface",  "static",     "void",
		"char",     "finally", "long",       "strictfp",   "volatile",
		"class",    "float",   "native",     "super",      "while",
		"const",    "for",     "new",        "switch",     
		"continue", "goto",    "package",    "synchronized",
		"true",     "false",   "null"};

	public static boolean isKeyword(String str) {
		for(int i=0; i<keywords.length; i++) {
			if (keywords[i].equals(str))
				return true;
		}
		return false;
	}

	public static boolean isValidName(String str) {
		if (str == null) 
			return false;
		if (str.length() == 0)
			return false;
		if (!isAlpha(str.charAt(0))) {
			return false;
		}
		for(int i=1; i<str.length(); i++) {
			if (!(isAlpha(str.charAt(i)) || 
					isUnderscore(str.charAt(i)) || 
					isDigit(str.charAt(i)))) {
				return false;
			}
		}
		if (isKeyword(str)) {
			return false;
		}
		return true;
	}

	public static ArrayList<String> getNamesFromCode(String code) {
		ArrayList<String> strs = new ArrayList<String>();
		int i = 0;
		while(i < code.length()) {
			char c = code.charAt(i);
			if (isAlpha(c) || isUnderscore(c)) {
				String str = "" + c;
				i++;
				while (i < code.length()) {
					c = code.charAt(i);
					if (isDigit(c) || isAlpha(c) || isUnderscore(c)) {
						str += c;
						i++;
					} else {
						break;
					}
				}

				boolean found = false;
				for(int j=0; j<strs.size(); j++) {
					if (strs.get(j).equals(str)) {
						found = true;
						break;
					}
				}
				if ((!found) && (!isKeyword(str)))
					strs.add(str);
			} else {
				i++;
			}
		}

		return strs;
	}

	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(args[0]));
		String temp = in.readLine();
		String str = "";
		while (temp != null) {
			str += temp + "\n";
			temp = in.readLine();
		}
		in.close();
		ArrayList<String> strs = getNamesFromCode(str);
		for(int i=0; i<strs.size(); i++) {
			System.out.println(strs.get(i));
		}
	}
}